﻿using System.Windows.Controls;
using Catel.Data;
using LprConfiger.Models;

namespace LprConfiger.ViewModels
{
    using Catel.MVVM;

    /// <summary>
    /// MainWindow view model.
    /// </summary>
    public class MainWindowViewModel : ViewModelBase
    {
        #region Variables
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
        /// </summary>
        public MainWindowViewModel()
            : base()
        {
            Machine = new Machine();


            // TODO: Move code below to constructor
            Connect = new Command(OnConnectExecute, OnConnectCanExecute);
            // TODO: Move code above to constructor

        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the title of the view model.
        /// </summary>
        /// <value>The title.</value>
        public override string Title { get { return "卡口配置工具"; } }

        // TODO: Register models with the vmpropmodel codesnippet
        // TODO: Register view model properties with the vmprop or vmpropviewmodeltomodel codesnippets

        /// <summary>
        /// Gets or sets the property value.
        /// </summary>
        public object SelectedItem
        {
            get { return GetValue<object>(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        /// <summary>
        /// Register the SelectedItem property so it is known in the class.
        /// </summary>
        public static readonly PropertyData SelectedItemProperty = RegisterProperty("SelectedItem", typeof(object));


        /// <summary>
        /// Gets or sets the property value.
        /// </summary>
        [Model]
        public Machine Machine
        {
            get { return GetValue<Machine>(MachineProperty); }
            private set { SetValue(MachineProperty, value); }
        }

        /// <summary>
        /// Register the Machine property so it is known in the class.
        /// </summary>
        public static readonly PropertyData MachineProperty = RegisterProperty("Machine", typeof(Machine));

        #endregion

        #region Commands
        // TODO: Register commands with the vmcommand or vmcommandwithcanexecute codesnippets
        /// <summary>
        /// Gets the Connect command.
        /// </summary>
        public Command Connect { get; private set; }


        /// <summary>
        /// Method to check whether the Connect command can be executed.
        /// </summary>
        /// <returns><c>true</c> if the command can be executed; otherwise <c>false</c></returns>
        private bool OnConnectCanExecute()
        {
            return SelectedItem != null;

        }

        /// <summary>
        /// Method to invoke when the Connect command is executed.
        /// </summary>
        private void OnConnectExecute()
        {
            // TODO: Handle command logic here
            System.Diagnostics.Debug.WriteLine(SelectedItem.ToString());
        }
        #endregion

        #region Methods
        // TODO: Create your methods here
        #endregion
    }
}
